import 'package:bxultimate/data/request/home_request.dart';
import 'package:bxultimate/shared/util/util_navigator.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'state.dart';


enum TaskDetailStatus {
  ACCEPT(2),
  COMPLETE(1),
  REFUSE(3);

  final int value;

  const TaskDetailStatus(this.value);

  static TaskDetailStatus? getByValue(int value) {
    return TaskDetailStatus.values.firstWhere((element) => element.value == value);
  }
}
class TaskDetailController extends GetxController {
  final TaskDetailState state = TaskDetailState();



  @override
  Future<void> onInit() async {
    // TODO: implement onInit
    super.onInit();

    getData();
  }

  getData() async {
    var task = await HomeRequest.getTaskDetail(Get.arguments);
    state.task = task.toJson();
  }

  updateTask(TaskDetailStatus taskDetailStatus) async{
    var data = {
      "id": Get.arguments,
      "isAccept": taskDetailStatus.value
    };
    await HomeRequest.updateTaskStatus(data);
    SmartDialog.showToast("操作成功");
    Get.back();
  }

  void toNavigator() {
    UtilNavigator.gotoAMap(toInstallCallBack: (){});
  }
}
